<template>
    <div id="header">
        <span class="head">
            
            <el-link href="/" :underline='false'><i class="el-icon-s-operation"></i><strong>&nbsp;海洋 Wiki 百科</strong></el-link>
            
            <el-dropdown v-show="showAva" class="ava">

                <el-avatar class="profile" size="medium" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />

                <el-dropdown-menu style="width:15%" slot="dropdown">
                    <div style="margin: 10% 10%">{{username}}</div>

                    <el-divider content-position="center"></el-divider>

                    <!-- <el-dropdown-item icon="el-icon-user">个人账户</el-dropdown-item>
                    <el-dropdown-item icon="el-icon-plus">邀请成员</el-dropdown-item> -->
                    <el-dropdown-item icon="el-icon-bangzhu">帮助中心</el-dropdown-item>
                    <el-dropdown-item icon="el-icon-close" style="color: red" @click.native="logout">退出登录</el-dropdown-item>
                
                </el-dropdown-menu>

                
                
            </el-dropdown>
            <el-button v-show="showLogin" style="float:right;" @click="toLogin">登录</el-button>
        </span>

    </div>
    
</template>

<script>
import request from "@/api/client.js"

export default {
    name: 'Myheader',
    data() {
        return {
            username: '----',
            showLogin: false,
            showAva: false
        }
    },
    mounted() {
        let username = localStorage.getItem("username")
        if(username != null) {
            this.showAva = true
            this.username = username
        } else {
            this.showLogin = true
        }
        
    },
    methods: {
        logout() {
            request.logout().then(resp => {
                localStorage.clear();
                sessionStorage.clear();
                this.$store.commit('RESET_STATE')
                this.$router.go(0)
            })
        },
        toLogin() {
            this.$router.push("/login")
        }
    }
}
</script>

<style>

.ava {
    float: right;
    display:block;
    height:40px;
    width: unset !important;
}

#header {
    position: relative;
    z-index: 10;
    height: 100%;
    width: auto;
    top: 0px;
    background-color: white;
    margin: 0 auto;
    /* padding: 5px; */
    border-radius: 0px;
    border-width: 0px;
    border-style: solid;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
}

.head {

  margin: 0px;
  padding: 10px 20px;
  line-height: 40px;
  display: block;
    font-size: 1.17em;
    
    font-weight: bold;
}

.profile {
    cursor: pointer;
    height: 40px;
    line-height: 40px;
}

</style>